package com.zyn.rsgl.controller;


import com.zyn.rsgl.pojo.Leave;
import com.zyn.rsgl.pojo.Todos;
import com.zyn.rsgl.service.TodosService;
import com.zyn.rsgl.utils.commonResult.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 审批表 前端控制器
 * </p>
 *
 * @author zcs
 * @since 2025-03-03
 */
@RestController
@RequestMapping("/rsgl/todo")
public class TodoController {

    @Resource
    private TodosService todosService;

    @GetMapping("/list")
    public R list(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String userId
    ) {
        System.out.println("hhhhhhhhhhhhhhhhhhhhhhhhhhh"+userId);
        return todosService.listPage(pageNum, pageSize, userId);
    }

    // 获取单个备忘录信息
    @GetMapping("/get/{todoId}")
    public R get(@PathVariable("todoId") String todoId) {
        Todos byId = todosService.getById(todoId);
        if (byId != null)
            return R.ok(byId);
        return R.fail("备忘录信息不存在");
    }

    // 添加备忘录信息
    @PostMapping("/add")
    public R add(@RequestBody Todos leave) {
        return todosService.save(leave) ? R.ok() : R.fail("添加失败");
    }

    // 修改备忘录信息
    @PutMapping("/update")
    public R update(@RequestBody Todos todos) {
        return todosService.updateById(todos) ? R.ok() : R.fail("修改失败");
    }

    // 删除备忘录信息
    @DeleteMapping("/delete/{todoId}")
    public R delete(@PathVariable("todoId") String todoId) {
        return todosService.removeById(todoId) ? R.ok() : R.fail("删除失败");
    }
}
